import java.util.ArrayList;
import java.util.Scanner;

/**
 * 根据结点的值删除单链表的结点
 */
public class HJ48 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            ArrayList<Integer> integers = new ArrayList<>();
            int num = scanner.nextInt();
            int head = scanner.nextInt();
            integers.add(head);
            for (int i = 0; i < num-1; i++) {
                int a = scanner.nextInt();
                int b = scanner.nextInt();

                integers.add(integers.indexOf(b)+1,a);
            }
            Integer reVal = (Integer)scanner.nextInt();

            integers.remove(reVal);

            for (Integer i : integers) {
                System.out.print(i+" ");
            }
        }
    }
}
